#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPushButton>
#include <QMessageBox>
#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QPushButton *button = new QPushButton("弹出消息对话框",this);
    connect(button,&QPushButton::clicked,this,&MainWindow::handle);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::handle()
{
    //创建一个消息对话框，我们指定了父元素，qt会帮我们销毁
    int result = QMessageBox::warning(this,"消息对话框","这是一个消息对话框",QMessageBox::Ok |QMessageBox::Cancel);
    if(result == QMessageBox::Ok){
        qDebug() << "Ok";
    }else if(result == QMessageBox::Cancel){
        qDebug() << "Cancel";
    }
}

